#!/usr/bin/env python3
#

import os
import sys

def __bin_dir():
    os.path.dirname(os.path.abspath(__file__))

def __get_last_result_dir():
    last_dir = 'my_result_2024-06-06_080808'
    for info in os.listdir('./'):
        if info[:10] == 'my_result_':
            if info > last_dir:
                last_dir = info

    return last_dir

if __name__ == '__main__':
    '''
        gcbs-c.py props.pg
    '''
    
    if len(sys.argv) != 2:
        print('gcbs-c.py need props file')
        exit(1)
    
    print('GCBS-OLTP-C Benchmark test')

    cmd_line = './runDatabaseDestroy.sh {} '.format(sys.argv[1])
    os.system(cmd_line)

    cmd_line = './runDatabaseBuild.sh {}'.format(sys.argv[1])
    os.system(cmd_line)

    cmd_line = './runBenchmark.sh {}'.format(sys.argv[1])
    os.system(cmd_line)
    
    result_dir = __get_last_result_dir()
    cmd_line = './generateGraphs.sh {}'.format(result_dir)
    os.system(cmd_line)

    cmd_line = './ReportPy.py {}'.format(result_dir)
    os.system(cmd_line)
    